package com.ruoyi.warehousemanager.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.warehousemanager.service.IMainCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/index")
public class MainCheckController extends BaseController {

    @Autowired
    private IMainCheckService checkService;

    @Autowired
    private ISysUserService userService;

    /**
     * 根据登陆用户名获取审批记录数量
     */
    @GetMapping(value = "/checknum/{username}")
    public AjaxResult getCheckNum(@PathVariable String username)
    {
        String userrole = userService.selectUserRoleGroup(username);
        if(userrole.equals("车间负责人")){
            return success(checkService.selectAllCheckNum(username));
        }
        else if(userrole.equals("工区负责人")){
            return success(checkService.selectCheckNum(username));
        }
        else if(userrole.equals("超级管理员")){
            return success(checkService.selectAllCheckNum(username));
        }
        else{
            return error("当前用户无角色！");
        }
    }

    /**
     * 根据登陆用户名获取在审记录数量
     */
    @GetMapping(value = "/checkin/{username}")
    public AjaxResult getCheckIn(@PathVariable String username)
    {
        String userrole = userService.selectUserRoleGroup(username);
        if(userrole.equals("车间负责人")){
            return success(checkService.selectAllCheckIn(username));
        }
        else if(userrole.equals("工区负责人")){
            return success(checkService.selectCheckIn(username));
        }
        else if(userrole.equals("超级管理员")){
            return success(checkService.selectAllCheckIn(username));
        }
        else{
            return error("当前用户无角色！");
        }
    }

    /**
     * 根据登陆用户名获取审批通过记录数量
     */
    @GetMapping(value = "/checkok/{username}")
    public AjaxResult getCheckOk(@PathVariable String username)
    {
        String userrole = userService.selectUserRoleGroup(username);
        if(userrole.equals("车间负责人")){
            return success(checkService.selectAllCheckOk(username));
        }
        else if(userrole.equals("工区负责人")){
            return success(checkService.selectCheckOk(username));
        }
        else if(userrole.equals("超级管理员")){
            return success(checkService.selectAllCheckOk(username));
        }
        else{
            return error("当前用户无角色！");
        }
    }

    /**
     * 根据登陆用户名获取审批未通过记录数量
     */
    @GetMapping(value = "/checkno/{username}")
    public AjaxResult getCheckNo(@PathVariable String username)
    {
        String userrole = userService.selectUserRoleGroup(username);
        if(userrole.equals("车间负责人")){
            return success(checkService.selectAllCheckNo(username));
        }
        else if(userrole.equals("工区负责人")){
            return success(checkService.selectCheckNo(username));
        }
        else if(userrole.equals("超级管理员")){
            return success(checkService.selectAllCheckNo(username));
        }
        else{
            return error("当前用户无角色！");
        }
    }
}
